package UIFree.slideshow
{
	import UIFree.ObjectEvent;
	import UIFree.effects.ef_flames;
	import UIFree.effects.uif_effect;
	import UIFree.uif_component;
	
	import flash.display.BlendMode;
	import flash.events.Event;
	import flash.geom.Matrix;


	public class ss_flameFade extends ss_slideFade {
		public function ss_flameFade(parent:uif_component, effectClass:Class, ax:int=0, ay:int=0, awidth:int=0, aheight:int=0, styleClass:String='') {
			super(parent, effectClass, ax, ay, awidth, aheight, styleClass);
			_outSlide.blendMode = BlendMode.LAYER;
//			_outSlide.filters = [new DropShadowFilter(5, 45, 0, 1, 6, 6, 2)];
		}
		
		override protected function doBeforeStart(): void {
			_outSlide.blendMode = BlendMode.LAYER;
		}
		
		protected function superDoStart(effectParams: Object): void {
			super.doStart(effectParams);
		}
		
		override protected function doStart(effectParams: Object): void {
			_inSlide.fx('light', _inSlide.light, 0).start(function(e: Event): void {
				superDoStart(effectParams);
			});
		} 
		
		override public function setEffect(effectClass: Class): void {
			super.setEffect(effectClass);
			
			effect.graphics.beginFill(0xFFFFFF, 0.01);
			effect.graphics.drawRect(0, 0, effect.width, effect.height);
			effect.blendMode 	= BlendMode.ALPHA;
			
			effect.addEvent(uif_effect.UPDATE, function(e: ObjectEvent): void {
				if (effect.frame <= effect.options.live) {
					var cMat: Matrix = new Matrix();
					var aScale : Number = (1 - effect.frame / effect.options.live) * (effect.options.scale - 1) + 1;
					cMat.scale(aScale, aScale);
					cMat.translate((width - outObject.width * aScale) / 2,
									(height - outObject.height * aScale) / 2);
					outObject.transform.matrix = cMat;
				} else {
					effect.stop();
					_inSlide.light = 1;
					inObject = outObject;
				}
			});
			
			effect.addEvent(ef_flames.UPDATEFLAME, function(e: ObjectEvent): void {
					var mat	: Matrix = new Matrix();
//					mat.rotate(e.object.options.flameRoll);
//					mat.scale(e.object.options.flameVolumeChange, e.object.options.flameVolumeChange);
					mat.translate(e.object.options.flameSpeed[0], e.object.options.flameSpeed[1]);
					mat.scale(e.object.options.flameVolumeChange[0], e.object.options.flameVolumeChange[1]);
					mat.concat(e.object.flame.transform.matrix);
					e.object.flame.transform.matrix = mat;
			});
		}
	}
}